﻿using System;
using System.Collections.Generic;

namespace RockPaperScissors.Web
{
    public class Message
    {
        public string Text;
        public Styles Style;

        public enum Styles
        {
            /// <summary>
            /// This is a sample of the 'Alert' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='alert'>...</span>
            /// </summary>
            Alert,
            /// <summary>
            /// This is a sample of the 'Approved' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='approved'>...</span>
            /// </summary>
            Approved,
            /// <summary>
            /// This is a sample of the 'Attention' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='attention'>...</span>
            /// </summary>
            Attention,
            /// <summary>
            /// This is a sample of the 'Camera' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='camera'>...</span>
            /// </summary>
            Camera,
            /// <summary>
            /// This is a sample of the 'Cart' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='cart'>...</span>
            /// </summary>
            Cart,
            /// <summary>
            /// This is a sample of the 'Doc' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='doc'>...</span>
            /// </summary>
            Doc,
            /// <summary>
            /// This is a sample of the 'Download' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='download'>...</span>
            /// </summary>
            Download,
            /// <summary>
            /// This is a sample of the 'Media' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='media'>...</span>
            /// </summary>
            Media,
            /// <summary>
            /// This is a sample of the 'Note' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='note'>...</span>
            /// </summary>
            Note,
            /// <summary>
            /// This is a sample of the 'Notice' style.  Use this style to denote very important information
            /// to your users.  This emits the following html: <span class='notice'>...</span>
            /// </summary>
            Notice
        }
    }

    public class Messages
    {
        private List<Message> m_messages;

        public Messages()
        {
            m_messages = new List<Message>();
        }

        public int MessageCount
        {
            get { return m_messages.Count; }
        }

        public void AddMessage(string message)
        {
            AddMessage(message, true, Message.Styles.Note);
        }

        public void AddMessage(string message, Message.Styles style)
        {
            AddMessage(message, true, style);
        }

        public void AddMessage(string message, bool ignoreIfDuplicate)
        {
            AddMessage(message, ignoreIfDuplicate, Message.Styles.Note);
        }

        public void AddMessage(string message, bool ignoreIfDuplicate, Message.Styles style)
        {
            // add a new message to the collection
            Message tmpMsg = new Message() { Text = message, Style = style };
            if ((m_messages.Exists(msg => msg == tmpMsg)) && (ignoreIfDuplicate))
            {
                // this item already exists, do no add it again
            }
            else
            {
                // add the new message to the collection
                if (message.Trim().Length > 0)
                {
                    m_messages.Add(tmpMsg);
                }
            }
        }

        public void ClearMessages()
        {
            m_messages.Clear();
        }

        public override string ToString()
        {
            // format the string
            string message = string.Empty;
            foreach (Message msg in m_messages)
            {
                message += String.Format("<span class='{0}'>{1}</span>",
                    msg.Style.ToString().ToLower(), msg.Text);
            }
            // return the html span code for this style
            return message;
        }
    }
}